<?php

require_once APPPATH."/controllers/BasePriv.php";
require_once APPPATH."/libraries/Tools.php";
require APPPATH."/libraries/FFmpeg.php";
use Aws\S3\S3Client;
class Quailty_material extends BasePriv{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', "url"));
        $this->load->model("Host_quailty_material_model", "table");
        $this->load->model("Host_user_material_model", "table_user_material");
        $this->user_material="user_material";//用户素材表
        $this->detail_msg="detail_msg";//操作详细表
        $this->quality_video="quality_video";//操作详细表
        $this->add_activity="add_activity";//操作详细表
    }
    //精选主页
    public function index(){
        //分页
        $arr=[];
        $arr['page']=intval($this->get('page'))>0 ? intval($this->get('page')) : 1;
        $arr['limit']=intval($this->get('limit'))>0 ? intval($this->get('limit')) : 10;
        //上下线状态筛选
        if(!empty($_GET['online'])){
            $arr['online']=$_GET['online'];
        }
        //话题筛选
        if(!empty($_GET['join_type_sub'])){
            $arr['join_type_sub']=$_GET['join_type_sub'];
        }
        //话题筛选
        if(!empty($_GET['is_join'])){
            $arr['is_join']=$_GET['is_join'];
        }
        //时间搜索
        if(!empty($_GET['time'])) {
            $get_time=$this->getStartAndEndTime("get");
            $start_time=strtotime($get_time[0]);
            $end_times=strtotime($get_time[1]);
            $end_time=$end_times+86400;
            $start=date("Y-m-d H:i:s",$start_time);
            $end=date("Y-m-d H:i:s",$end_time);
            $arr['start_time'] =$start;
            $arr['end_time'] =$end;
        }
        //查询数据（原始素材）
        $res=$this->table->all($arr);
        //查询分类
        $type=$this->table->types();
        //查询话题
        $type_sub=$this->table->type_sub("",2);
        //查询所有用户
        $all_users=$this->table->users("users");
        //显示话题和分类
        if(!empty($res['row'])){
            foreach($res['row'] as $k=>&$v){
                foreach($all_users as $kk=>$vv){
                    if($v['uuid']==$vv['uuid']){
                        $v['user_name']=$vv['nick_name'];
                    }
                }
                foreach($type_sub as $kkk=>$vvv){
                    if($v['quality_join_type_sub']==$vvv['id']){
                        $v['quality_join_type_sub_name']=$vvv['sub_title'];
                    }
                }
            }
        }
        //把数据带入视图
        $data['data']=$res;
        $data['page']=$arr['page'];
        $data['limit']=$arr['limit'];
        $data['type_sub']=$type_sub;
        $data['html']=1;
        $this->layout("material/quailty_material/index",$data);
    }
////////////////////////////////////////////////////////////////视频精品开始//////////////////////////////////////////////////////////////////////

    /**
     * 添加视频精品
     */
    public function add_quailty(){
        //查询所有后台上传人物
        $users=$this->table->all_users();
        $data['users']=$users;
        $this->layout("material/quailty_material/add_quailty",$data);
    }

    /**
     * 添加到普通
     */
    public function save_quality(){
        if(empty($_POST['fenlei'])){
            response(-1,"分类不能为空");
        }
        if(empty($_POST['huati'])){
            response(-1,"话题不能为空");
        }
        if(empty($_POST['video_desc'])){
            response(-1,"视频描述不能为空");
        }
        if(empty($_POST['video_url1'])){
            response(-1,"请上传视频");
        }
        if(empty($_POST['share_pic'])){
            response(-1,"请上传分享封面");
        }
        if(empty($_POST['hengping_pic'])){
            response(-1,"请上传横屏封面");
        }
        if(mb_strlen($_POST['video_desc'])>30){
            response(-1,"已超过最大30字");
        }
//        var_dump($_POST);exit;
        if(empty($_POST['video_url2'])){
            //用ffmpeg截取视频第一帧作为封面
            $ffmpeg = new FFmpeg(false);
            $image_dir=$this->upload_dir();
            $true=$ffmpeg->getCoverFromVideo($_POST['video_url1'],$image_dir['uploadpath']);
            if($true){
                $data['quatily_pic']=$image_dir['savehttp'];
            }
        }else{
            $data['quatily_pic']=$_POST['video_url2'];
        }
        //获取视屏时长
        $ffmpeg = new FFmpeg(false);
        $data['duration']=$ffmpeg->getVideoLen($_POST['video_url1']);

        //获取视频宽高
        $wh=$ffmpeg->getVideoDetail($_POST['video_url1']);
        $data['width1']=$wh['width'];
        $data['height1']=$wh['height'];
        //获取视频封面第一帧
        $image_dir1=$this->upload_dir();
        $true=$ffmpeg->getCoverFromVideo($_POST['video_url1'],$image_dir1['uploadpath']);
        $data['first_pic2']=$image_dir1['savehttp'];

        //用户信息
        $users=$this->table->one("users",["uuid"=>$_POST['users']],"uuid,nick_name,nick_pic");
        $key1=rand(1000,10000);
        $key2=rand(10000,20000);
        $key3=rand(1000,10000);
        $key4=rand();
        $key=$key1.$key2.$key3.$key4;
        $data['quality_uuid']=$key;
        $data['quality_share_pic']=$_POST['share_pic'];
        $data['quality_hengping_pic']=$_POST['hengping_pic'];
        $data['quality_join_type']=$_POST['fenlei'];
        $data['quality_join_type_sub']=$_POST['huati'];
        $data['video_url']=$_POST['video_url1'];
//        $data['video_url']=$_POST['video_url1'];
        $data['quality_desc']=$_POST['video_desc'];
        $data['online']=2;//上线状态
        $data['del3']=2;//未删除
        $data['is_join']=2;//加入话题
        $data['uuid']=$users['uuid'];
        $data['nick_name']=$users['nick_name'];
        $data['nick_pic']=$users['nick_pic'];
        $data['add_time']=date("Y-m-d H:i:s",time());
        $re11=$ffmpeg->getVideoDetail($data['video_url']);
//        var_dump($re11);exit;
        $data['width1']=$re11['width'];
        $data['height1']=$re11['height'];
//        var_dump($data);exit;
        //先加入用户的投稿列表，再添加到精品视频列表
        $res=$this->table->add_material($data);
//        var_dump($res);exit;

        if($res){
            //把数据推送给未来电视媒资
            $re=$this->table_user_material->push($res,"product");
            response(0,"添加成功",base_url("material/quailty_material/index"));
        }else{
            response(-1,"添加失败");
        }
    }

    /**
     * 添加到精选
     */
    public function save_join_quality(){
        if(empty($_POST['fenlei'])){
            response(-1,"分类不能为空");
        }
        if(empty($_POST['huati'])){
            response(-1,"话题不能为空");
        }
        if(empty($_POST['video_desc'])){
            response(-1,"视频描述不能为空");
        }
        if(empty($_POST['video_url1'])){
            response(-1,"请上传视频");
        }
        if(empty($_POST['share_pic'])){
            response(-1,"请上传分享封面");
        }
        if(empty($_POST['hengping_pic'])){
            response(-1,"请上传横屏封面");
        }
        if(mb_strlen($_POST['video_desc'])>30){
            response(-1,"已超过最大30字");
        }
//        var_dump($_POST);exit;
        if(empty($_POST['video_url2'])){
            //用ffmpeg截取视频第一帧作为封面
            $ffmpeg = new FFmpeg(false);
            $image_dir=$this->upload_dir();
            $true=$ffmpeg->getCoverFromVideo($_POST['video_url1'],$image_dir['uploadpath']);
            if($true){
                $data['quatily_pic']=$image_dir['savehttp'];
            }
        }else{
            $data['quatily_pic']=$_POST['video_url2'];
        }
        //获取视屏时长
        $ffmpeg = new FFmpeg(false);
        $data['duration']=$ffmpeg->getVideoLen($_POST['video_url1']);
        //获取视频宽高
        $wh=$ffmpeg->getVideoDetail($_POST['video_url1']);
        $data['width1']=$wh['width'];
        $data['height1']=$wh['height'];
        //获取视频封面第一帧
        $image_dir1=$this->upload_dir();
        $true=$ffmpeg->getCoverFromVideo($_POST['video_url1'],$image_dir1['uploadpath']);
        $data['first_pic2']=$image_dir1['savehttp'];

        //用户信息
        $users=$this->table->one("users",["uuid"=>$_POST['users']],"uuid,nick_name,nick_pic");
        $key1=rand(1000,10000);
        $key2=rand(10000,20000);
        $key3=rand(1000,10000);
        $key4=rand();
        $key=$key1.$key2.$key3.$key4;
        $data['quality_uuid']=$key;
        $data['quality_share_pic']=$_POST['share_pic'];
        $data['quality_hengping_pic']=$_POST['hengping_pic'];
        $data['quality_join_type']=$_POST['fenlei'];
        $data['quality_join_type_sub']=$_POST['huati'];
        $data['video_url']=$_POST['video_url1'];
//        $data['video_url']=$_POST['video_url1'];
        $data['quality_desc']=$_POST['video_desc'];
        $data['online']=2;//上线状态
        $data['del3']=2;//未删除
        $data['is_join']=2;//加入话题
        $data['uuid']=$users['uuid'];
        $data['nick_name']=$users['nick_name'];
        $data['nick_pic']=$users['nick_pic'];
        $data['add_time']=date("Y-m-d H:i:s",time());
        $re11=$ffmpeg->getVideoDetail($data['video_url']);
        $data['width1']=$re11['width'];
        $data['height1']=$re11['height'];
        //先加入用户的投稿列表，再添加到精品视频列表
        $res=$this->table->add_join_material($data);
        if($res){
            //把数据推送给未来电视媒资
            $this->table_user_material->push($res,"product");
            response(0,"添加成功",base_url("material/quailty_material/index"));
        }else{
            response(-1,"添加失败");
        }
    }

    /**
     * 修改精品视频
     */
    public function edit_quality(){
        $video_uuid=$_REQUEST['video_uuid'];
        if(empty($video_uuid)){
            response(-1,"缺少参数");
        }
        $res=$this->table->one("quality_video",["id"=>$video_uuid]);
        $data['data']=$res;
        $data['type']=$this->table->types();
        $data['type_sub']=$this->table->type_sub(['sub_type'=>$res['quality_join_type']]);
        //查询所有后台上传人物
        $users=$this->table->all_users();
        $data['users']=$users;
        if($res['is_dubs']==2){
            $this->layout("material/quailty_material/edit_quality",$data);
        }else if($res['is_dubs']==1){
            //在根据视频uuid去查video表
            $video=$this->table->one("video",["video_uuid"=>$res['quality_uuid']]);
            $data['video']=$video;
            $this->layout("material/quailty_material/edit_quality_dub",$data);
        }
    }

    /**
     *保存精品视频修改
     */
    public function save_edit_quality(){
        if(empty($_POST['fenlei'])){
            response(-1,"分类不能为空");
        }
        if(empty($_POST['huati'])){
            response(-1,"话题不能为空");
        }
        if(empty($_POST['video_desc'])){
            response(-1,"视频描述不能为空");
        }
        if(empty($_POST['share_pic'])){
            response(-1,"请上传分享封面");
        }
        if(mb_strlen($_POST['video_desc'])>30){
            response(-1,"已超过最大30字");
        }
        //
        $id=$_REQUEST['id'];
        if(empty($id)){
            response(-1,"缺少参数");
        }
        $res=$this->table->one("quality_video",["id"=>$id],"id,is_join,user_material_id,quality_video_url");
        //查询分类名称
        $results=$this->table->one("type_sub",["id"=>$_POST['huati']]);
        //如果修改了视频地址就需要重新转码
        if($res['quality_video_url']!=$_POST['video_url1']){
            $data['transcode_status']=0;
            $data['transcode_count']=0;
            $data['transcode_msg']="";
            $data['quality_video_url']="";
        }

        //
        $data['quality_join_type']=$_POST['fenlei'];
        $data['quality_join_type_sub']=$_POST['huati'];
//        $data['quality_video_url']=$_POST['video_url1'];
        $data['video_url']=$_POST['video_url1'];
        $data['quatily_pic']=$_POST['video_url2'];
        $data['quality_share_pic']=$_POST['share_pic'];
        $data['quality_hengping_pic']=$_POST['hengping_pic'];
        $data['quality_desc']=$_POST['video_desc'];
        //获取视屏时长
        $ffmpeg = new FFmpeg();
        $data['duration']=$ffmpeg->getVideoLen($_POST['video_url1']);
        //获取视频宽高
        $re11=$ffmpeg->getVideoDetail($_POST['video_url1']);
//        var_dump($ffmpeg);
//        var_dump($_POST);exit;

        $data['width1']=$re11['width'];
        $data['height1']=$re11['height'];

        //获取视频封面第一帧
        $image_dir1=$this->upload_dir();
        $true=$ffmpeg->getCoverFromVideo($_POST['video_url1'],$image_dir1['uploadpath']);
        $data['first_pic2']=$image_dir1['savehttp'];

        if(!empty($res['user_material_id'])){
            //这是加入话题
            $res1=$this->table->edit_material($data,$res);
            if($res1){
                response(0,"修改成功");
            }else{
                response(-1,"修改失败");
            }
        }else if(empty($res['user_material_id'])){
            //没加入话题
            $res2=$this->table->update("quality_video",$data,['id'=>$id]);
            if($res2){
                response(0,"修改成功");
            }else{
                response(-1,"修改失败");
            }
        }else{
            response(-1,"数据异常");
        }
    }

    /**
     *保存精品视频修改
     */
    public function edit_dub_save(){
        if(empty($_POST['fenlei'])){
            response(-1,"请选择分类");
        }
        if(empty($_POST['huati'])){
            response(-1,"请选择话题");
        }
        if(empty($_POST['users'])){
            response(-1,"请选择用户");
        }
        if(empty($_POST['material'])){
            response(-1,"请选择关联素材");
        }
        if(empty($_POST['video_desc'])){
            response(-1,"视频标题不能为空");
        }
        if(empty($_POST['video_url2'])){
            response(-1,"视频封面不能为空");
        }
        if(empty($_POST['share_pic'])){
            response(-1,"请上传分享封面");
        }
        if(empty($_POST['video_url'])){
            response(-1,"视频地址不能为空");
        }
        //在去根据用户uuid去用户表查询，呢称头像
        $users=$this->table->one("users",['uuid'=>$_POST['users']]);
        if(empty($users)){
            response(-1,"请重新选择用户");
        }
        //在去根据视频uuid去原始素材表查询，视频和背景音乐地址
        $video=$this->table->one("video",['video_uuid'=>$_POST['material']]);
        if(empty($video)){
            response(-1,"请重新选择关联素材");
        }
        $quality=$this->table->one("quality_video",['id'=>$_POST['id']]);
        $data['quality_uuid']=$_POST['material'];
        $data['quality_join_type']=$_POST['fenlei'];
        $data['quality_join_type_sub']=$_POST['huati'];
        $data['quality_video_url']=$_POST['video_url'];
        $data['quatily_pic']=$_POST['video_url2'];
        $data['quality_share_pic']=$_POST['share_pic'];
        $data['quality_desc']=$_POST['video_desc'];
        $data['duration']=$_POST['duration'];
        $data['nick_name']=$users['nick_name'];
        $data['nick_pic']=$users['nick_pic'];
        $data['uuid']=$_POST['users'];
        $data['width1']=$video['width'];
        $data['height1']=$video['height'];
        $data['first_pic2']=$video['first_pic1'];
        //先去插入到user_material表，再去加入到精品视频表
        $res=$this->table->edit_dub_save($data,$video,$quality['user_material_id'],$quality['id']);
//        var_dump($res);exit;
        if($res){
            response(0,"修改成功");
        }else{
            response(-1,"修改失败");
        }
    }
///////////////////////////////////////////////////////////////////////视频精品结束/////////////////////////////////////////////////////////////////////////////////

    /**
     * 添加配音精品
     */
    public function add_quality_dub(){
        //查询所有后台上传人物
        $users=$this->table->all_users();
        $data['users']=$users;
        $this->layout("material/quailty_material/add_quality_dub",$data);
    }

    /**
     * 保存精品配音到精选
     */
    public function save_join_quality_dub(){
        if(empty($_POST['fenlei'])){
            response(-1,"请选择分类");
        }
        if(empty($_POST['huati'])){
            response(-1,"请选择话题");
        }
        if(empty($_POST['users'])){
            response(-1,"请选择用户");
        }
        if(empty($_POST['material'])){
            response(-1,"请选择关联素材");
        }
        if(empty($_POST['video_desc'])){
            response(-1,"视频描述不能为空");
        }
        if(empty($_POST['video_url2'])){
            response(-1,"视频封面不能为空");
        }
        if(empty($_POST['video_url'])){
            response(-1,"视频地址不能为空");
        }
        if(empty($_POST['share_pic'])){
            response(-1,"请上传分享封面");
        }
        if(empty($_POST['hengping_pic'])){
            response(-1,"请上传横屏封面");
        }
        if(mb_strlen($_POST['video_desc'])>30){
            response(-1,"已超过最大30字");
        }
        //在去根据用户uuid去用户表查询，呢称头像
        $users=$this->table->one("users",['uuid'=>$_POST['users']]);
        if(empty($users)){
            response(-1,"请重新选择用户");
        }
        //在去根据视频uuid去原始素材表查询，视频和背景音乐地址
        $video=$this->table->one("video",['video_uuid'=>$_POST['material']]);
        if(empty($video)){
            response(-1,"请重新选择关联素材");
        }
        $data['quality_uuid']=$_POST['material'];
        $data['quality_join_type']=$_POST['fenlei'];
        $data['quality_join_type_sub']=$_POST['huati'];
        $data['quality_video_url']=$_POST['video_url'];
        $data['quatily_pic']=$_POST['video_url2'];
        $data['quality_share_pic']=$_POST['share_pic'];
        $data['quality_hengping_pic']=$_POST['hengping_pic'];
        $data['quality_desc']=$_POST['video_desc'];
        $data['duration']=$_POST['duration'];
        $data['nick_name']=$users['nick_name'];
        $data['nick_pic']=$users['nick_pic'];
        $data['uuid']=$_POST['users'];
        $data['online']=2;
        $data['del3']=2;
        $data['is_join']=2;
        $data['transcode_status']=2;
        $data['is_dubs']=1;
        $data['add_time']=date("Y-m-d H:i:s",time());
        $data['width1']=$video['width'];
        $data['height1']=$video['height'];
        $data['first_pic2']=$video['first_pic1'];
        //先去插入到user_material表，再去加入到精品视频表
        $res=$this->table->add_quality_dub($data,$video);
//        var_dump($res);exit;
        if($res){
            //把数据推送给未来电视媒资
            $this->table_user_material->push($res,"product");
            response(0,"添加成功");
        }else{
            response(-1,"添加失败");
        }
    }

    /**
     * 保存精品配音到普通
     */
    public function save_join_dub(){
        if(empty($_POST['fenlei'])){
            response(-1,"请选择分类");
        }
        if(empty($_POST['huati'])){
            response(-1,"请选择话题");
        }
        if(empty($_POST['users'])){
            response(-1,"请选择用户");
        }
        if(empty($_POST['material'])){
            response(-1,"请选择关联素材");
        }
        if(empty($_POST['video_desc'])){
            response(-1,"视频描述不能为空");
        }
        if(empty($_POST['video_url2'])){
            response(-1,"视频封面不能为空");
        }
        if(empty($_POST['video_url'])){
            response(-1,"视频地址不能为空");
        }
        if(empty($_POST['share_pic'])){
            response(-1,"请上传分享封面");
        }
        if(empty($_POST['hengping_pic'])){
            response(-1,"请上传横屏封面");
        }
        if(mb_strlen($_POST['video_desc'])>30){
            response(-1,"已超过最大30字");
        }
        //在去根据用户uuid去用户表查询，呢称头像
        $users=$this->table->one("users",['uuid'=>$_POST['users']]);
        if(empty($users)){
            response(-1,"请重新选择用户");
        }
        //在去根据视频uuid去原始素材表查询，视频和背景音乐地址
        $video=$this->table->one("video",['video_uuid'=>$_POST['material']]);
        if(empty($video)){
            response(-1,"请重新选择关联素材");
        }
        $data['quality_uuid']=$_POST['material'];
        $data['quality_join_type']=$_POST['fenlei'];
        $data['quality_join_type_sub']=$_POST['huati'];
        $data['quality_video_url']=$_POST['video_url'];
        $data['quatily_pic']=$_POST['video_url2'];
        $data['quality_share_pic']=$_POST['share_pic'];
        $data['quality_hengping_pic']=$_POST['hengping_pic'];
        $data['quality_desc']=$_POST['video_desc'];
        $data['duration']=$_POST['duration'];
        $data['nick_name']=$users['nick_name'];
        $data['nick_pic']=$users['nick_pic'];
        $data['uuid']=$_POST['users'];
        $data['online']=2;
        $data['del3']=2;
        $data['is_join']=2;
        $data['transcode_status']=2;
        $data['is_dubs']=1;
        $data['add_time']=date("Y-m-d H:i:s",time());
        $data['width1']=$video['width'];
        $data['height1']=$video['height'];
        $data['first_pic2']=$video['first_pic1'];
        //先去插入到user_material表，再去加入到精品视频表
        $res=$this->table->add_dub($data,$video);
//        var_dump($res);exit;
        if($res){
            //把数据推送给未来电视媒资
            $this->table_user_material->push($res,"product");
            response(0,"添加成功");
        }else{
            response(-1,"添加失败");
        }
    }

    /**
     * 修改
     */

    /**
     * 删除精品
     */
    public function drop_quality(){
        $video_uuid=$_POST['video_uuid'];
        if(empty($video_uuid)){
            response(-1,"缺少参数");
        }
        $res=$this->table->drop_quality($video_uuid);
        if($res){
            //拼接数据入库
            $data['user_id']=$this->userInfo['role_id'];
            $data['user_name']=$this->userInfo['name'];
            $data['detail_msg']=json_encode($res);
            $data['add_time']=date("Y-m-d H:i:s",time());
            $this->table->add($this->detail_msg,$data);
            response(0,"删除成功");
        }else{
            response(-1,"删除失败");
        }
    }

    /**
     * 获取分类
     */
    public function types(){
        $biaoqian=$this->table->types();
        if($biaoqian){
            response(0,"获取成功",$biaoqian);
        }else{
            response(-1,"获取失败",$biaoqian);
        }
    }

    /**
     * 获取话题
     */
    public function type_sub(){
        $where['sub_type']=$_POST['type_id'];
        $biaoqian=$this->table->type_sub($where);
        if($biaoqian){
            response(0,"获取成功",$biaoqian);
        }else{
            response(-1,"当前分类下没有话题",$biaoqian);
        }
    }

    /**
     * 获取关联素材
     */
    public function material(){
        $where['video_join_sub']=$_POST['type_id'];
        $biaoqian=$this->table->material($where);
        if($biaoqian){
            response(0,"获取成功",$biaoqian);
        }else{
            response(-1,"当前分类下没有关联素材",$biaoqian);
        }
    }

    /**
     * 单个关联素材详情
     */
    public function material_detail(){
        $where['video_uuid']=$_POST['type_id'];
        $biaoqian=$this->table->material_detail($where);
        if($biaoqian){
            response(0,"获取成功",$biaoqian);
        }else{
            response(-1,"当前分类下没有关联素材",$biaoqian);
        }
    }

    /**
     * 弃用主页
     */
    public function drop(){
        //分页
        $arr=[];
        $arr['page']=intval($this->get('page'))>0 ? intval($this->get('page')) : 1;
        $arr['limit']=intval($this->get('limit'))>0 ? intval($this->get('limit')) : 10;
        //话题筛选
        if(!empty($_GET['join_type_sub'])){
            $arr['join_type_sub']=$_GET['join_type_sub'];
        }
        //话题筛选
        if(!empty($_GET['is_join'])){
            $arr['is_join']=$_GET['is_join'];
        }
        //时间搜索
        if(!empty($_GET['time'])) {
            $get_time=$this->getStartAndEndTime("get");
            $start_time=strtotime($get_time[0]);
            $end_times=strtotime($get_time[1]);
            $end_time=$end_times+86400;
            $start=date("Y-m-d H:i:s",$start_time);
            $end=date("Y-m-d H:i:s",$end_time);
            $arr['start_time'] =$start;
            $arr['end_time'] =$end;
        }
        //查询数据（原始素材）
        $res=$this->table->drop($arr);
        //查询分类
        $type=$this->table->types();
        //查询话题
        $type_sub=$this->table->type_sub("",2);
        //查询所有用户
        $all_users=$this->table->users("users");
        //显示话题和分类
        if(!empty($res['row'])){
            foreach($res['row'] as $k=>&$v){
                foreach($all_users as $kk=>$vv){
                    if($v['uuid']==$vv['uuid']){
                        $v['user_name']=$vv['nick_name'];
                    }
                }
                foreach($type_sub as $kkk=>$vvv){
                    if($v['quality_join_type_sub']==$vvv['id']){
                        $v['quality_join_type_sub_name']=$vvv['sub_title'];
                    }
                }
            }
        }
        //把数据带入视图
        $data['data']=$res;
        $data['page']=$arr['page'];
        $data['limit']=$arr['limit'];
        $data['type_sub']=$type_sub;
        $data['html']=2;
        $this->layout("material/quailty_material/drop",$data);
    }

    /**
     * 加入活动
     */
    public function join_activity(){
        $video_uuid=$_POST['video_uuid'];
        if(empty($video_uuid)){
            response(-1,"缺少参数");
        }
        //先去活动表查询是否已经加入了
        $data1=$this->table->one($this->add_activity,['material_id'=>"pgc_".$video_uuid]);
        if(!empty($data1)){
            response(-1,"该条数据已经加入活动");
        }
        //先去查询要加入的数据
        $res=$this->table->one($this->quality_video,['id'=>$video_uuid]);
        //拼接要加入的数据
        $data['video_uuid']=$res['quality_uuid'];
        $data['fenlei']=$res['quality_join_type'];
        $data['huati']=$res['quality_join_type_sub'];
        $data['video_title']=$res['quality_desc'];
        $data['shuping_pic']=$res['quatily_pic'];
        $data['hengping_pic']=$res['quality_hengping_pic'];
        $data['fenxiang_pic']=$res['quality_share_pic'];
        $data['video_url']=$res['quality_video_url'];
        $data['video_time']=$res['duration'];
        $data['material_source']="pgc";
        $data['material_id']="pgc_".$res['id'];
        $data['add_time']=date("Y-m-d H:i:s",time());
        $data['update_time']=date("Y-m-d H:i:s",time());
        $res=$this->table->add($this->add_activity,$data);
        if($res){
            response(0,"加入活动成功");
        }else{
            response(0,"加入活动失败");
        }
    }


}